﻿using System;

using Moe.ECamel.Client.Controllers;
using Moe.ECamel.Client.WinForms.Common;
using Moe.ECamel.Common.Entities;

namespace Moe.ECamel.Client.WinForms.Forms
{
	public partial class ChangePasswordForm : ECamelForm
	{
		private readonly SystemController _controller;

		public ChangePasswordForm()
		{
			InitializeComponent();
		}

		public ChangePasswordForm(SystemController controller)
			: this()
		{
			this._controller = controller;
		}

		private void ConfirmationButton_Click(object sender, EventArgs e)
		{
			if (NewPassword1TextBox.Text != NewPassword2TextBox.Text)
			{
				ECamelHelper.ShowMessage(MessageIds.ChangePasswordFailedPasswordsNotMatch);
				return;
			}

			var error = _controller.ChangeCurrentUserPassword(_controller.CurrentLoginInfo.UserId, OldPasswordTextBox.Text, NewPassword1TextBox.Text);
			if (error != null)
			{
				ECamelHelper.ShowMessage(error);
				return;				
			}

			this.Close();
		}

		private void CancellationButton_Click(object sender, EventArgs e)
		{
			this.Close();
		}
	}
}